package com.javatest2;

import edu.princeton.cs.algs4.Count;
import edu.princeton.cs.algs4.Counter;
import edu.princeton.cs.algs4.Date;

import java.util.Arrays;

/**
 * @author LL
 * @project 反转
 * @create 2021-01-13 20:45
 */
public class Subject2 {

    //方法一:
    public static void test1(){
        int[] a = {1,3,4,5,6};
        for (int i = 0,j = a.length -1; i < j; i++,j--) {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
        System.out.println(Arrays.toString(a));
    }

    //方法二：
    public static void test2(){
        int[] a = {1,3,4,5,6};
        for (int i = 0; i < a.length/2; i++) {
            int temp = a[i];
            a[i] = a[a.length-i -1];
            a[a.length-i -1] = temp;
        }
        System.out.println(Arrays.toString(a));
    }


    public static void main(String[] args) {
        test2();
    }
}
